#! /usr/bin/python3

import sys

names = "  \""
ulen = 0
offsets, flags = ([], [])
acclen = 0
pnames = []

for line in sys.stdin:
  line = line.strip ()
  parts = line.split (' ')
  offsets.append (acclen)
  nm = parts[0]
  names += '%s\\0' % nm
  acclen += len (nm) + 1
  ulen += len (nm) + 2
  pnames.append (nm)
  if ulen > 64:
    names += "\"\n  \""
    ulen = 0

  if parts[2] == '0':
    flags.append (parts[1])
  else:
    p2 = parts[2].split (',')
    flags.append (' | '.join ([parts[1]] + [('BC_%s_FORM' % s.upper ()) for s in p2]))


print ("static const char OPC_NAMES[] =\n%s\";\n" % names[:-2])

print ("static const bcode_instr BCODE_INSTR[] =\n{")

for i, _ in enumerate (flags):
  print ("  { %s, %s },   // %s" % (offsets[i], flags[i], pnames[i]))

print ("  { 0, 0 }\n};")

ulen = 2
print ("\n\nconst void* const LABELS[] =\n{\n  ", end = '')
for name in pnames:
  s = "P_(" + name.replace('.', '').upper () + "),"
  ulen += len (s)
  if ulen > 64:
    print ("\n  %s" % s, end = '')
    ulen = 2
  else:
    print (" %s" % s, end = '')
    ulen += 1

print ("\n};")
